package com.example.core.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.example.core.utils.UserUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashSet;
import java.util.Set;

@Data
@ApiModel(value = "权限基类")
public class BaseAuthPo<T> extends BaseCreatePo {

    @ApiModelProperty(value = "可读人员id")
    private transient Set<String> sysReaderIds = new HashSet<>();

    @ApiModelProperty(value = "可读人员名称")
    private transient Set<String> sysReaderNames = new HashSet<>();

    @ApiModelProperty(value = "可编辑人员id")
    private transient Set<String> sysEditorIds = new HashSet<>();

    @ApiModelProperty(value = "可编辑人员名称")
    private transient Set<String> sysEditorNames = new HashSet<>();

    @ApiModelProperty(value = "可下载人员id")
    private transient Set<String> sysDownloadIds = new HashSet<>();

    @ApiModelProperty(value = "可下载人员名称")
    private transient Set<String> sysDownloadNames = new HashSet<>();

    @ApiModelProperty(value = "可删除人员id")
    private transient Set<String> sysDeleteIds = new HashSet<>();

    @ApiModelProperty(value = "可删除人员名称")
    private transient Set<String> sysDeleteNames = new HashSet<>();

    @ApiModelProperty(value = "默认可读")
    @TableField(value = "auth_reader_flag")
    public boolean authReaderFlag;

    @Override
    public void recalculateFields() {
        super.recalculateFields();
        if (!this.sysReaderIds.contains(UserUtils.getUserId())) {
            this.sysReaderIds.add(UserUtils.getUserId());
        }
    }
}
